package mul.UI;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import android.preference.Preference.OnPreferenceClickListener;
import android.util.Log;

public class SettingsActivity extends PreferenceActivity {
	
	private SharedPreferences.Editor editor;
	private CheckBoxPreference music;
	private CheckBoxPreference soundEffects;
	
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.layout.settings);
        SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
		editor = settings.edit();
		music = (CheckBoxPreference)findPreference("Music");
		soundEffects = (CheckBoxPreference)findPreference("Sound");
		music.setChecked(settings.getBoolean("musicOn", true));
		soundEffects.setChecked(settings.getBoolean("soundOn", true));

		music.setOnPreferenceClickListener(new OnPreferenceClickListener() {
		    public boolean onPreferenceClick(Preference preference) {
		    	editor.putBoolean("musicOn", music.isChecked());
		    	Log.w("debugging", "music set");
		    	editor.commit();
		    	return true;
		    }
		});
		soundEffects.setOnPreferenceClickListener(new OnPreferenceClickListener() {
		    public boolean onPreferenceClick(Preference preference) {
		    	editor.putBoolean("soundOn", soundEffects.isChecked());
		    	Log.w("debugging", "sound set");
		    	editor.commit();
		    	return true;
		    }
		});
	}
}
